package com.smrs.asn.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.util.Assert;

import com.jof.framework.dao.hibernate.BaseDAOHibernateImpl;
import com.jof.framework.util.Pager;
import com.smrs.asn.model.AsnDetailModel;
import com.smrs.asn.model.AsnHeaderModel;
import com.smrs.goods.model.GoodsSkuModel;


public class AsnDetailDao extends BaseDAOHibernateImpl<AsnDetailModel, Long>{
	public Pager<AsnDetailModel> findBySkuAndAsnHeader(GoodsSkuModel sku,AsnHeaderModel asnHeader,Pager<AsnDetailModel> pager){
		String queryString = " from AsnDetailModel where 1=1";
		if(sku!=null){
			queryString = queryString + " and skuId="+sku.getId();
		}
		if(asnHeader!=null){
			queryString = queryString + " and asnId=" +asnHeader.getId();
		}
		Object values[]=new Object[]{};
		Query query = this.createHQLQuery(queryString, values);
		this.setPageParameterToQuery(query, pager);
		Long count=this.countHQLResult(queryString, values);
		List list = query.list();		
		Pager<AsnDetailModel> tempPager = Pager.cloneFromPager(pager, count, list);
		return tempPager;
	}

	public List<AsnDetailModel> findByAsnHeader(AsnHeaderModel asnHeader){
		Assert.notNull(asnHeader, "入库单不能为空");
		String queryString = " from AsnDetailModel where 1=1";
		if(asnHeader!=null){
			queryString = queryString + " and asnId=" +asnHeader.getId();
		}
		Object values[]=new Object[]{};
		Query query = this.createHQLQuery(queryString, values);
		List list = query.list();
		return list;
	}

	
}
